// pages/basics/schedule/schedule.js
const app = getApp();
const util = require("../../../utils/util.js");
const rq = require("../../../utils/https.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {

    rooms: [], //会议室
    roomIndex: null,
    date: '', //日期
  },
  onLoad(){
    //设置今天的日期
    this.setData({
      today: util.formatTime(new Date()).substring(0, 10)
    })
    this.setData({
      users: wx.getStorageSync('users'),
      rooms: wx.getStorageSync('rooms'),
      user_id: wx.getStorageSync('user_id'),
      user_name: wx.getStorageSync('user_name'),
      user_ids: [wx.getStorageSync('user_id')],
      user_names: wx.getStorageSync('user_name'),
    })
  },
  //选择完成后提示当天已有的安排
  PickerChange(e) {
    let that = this;
    let roomIndex = e.detail.value
    let room_id = this.data.rooms[roomIndex].room_id;
    let date = this.data.date
    if (date) {
      rq.request('meeting/date', { room_id: room_id, date: date }, function (result) {
        if (result.code == 0) {
          console.log(result.data);
          that.showModal(result.data);
        } else {
          wx.showToast({
            title: result.msg,
            icon: 'none'
          })
        }
      })
    }
    this.setData({
      roomIndex: roomIndex
    })
  },
  DateChange(e) {
    let that = this;
    let date = e.detail.value
    console.log(this.data.roomIndex)
    if (this.data.roomIndex) {
      let room_id = this.data.rooms[this.data.roomIndex].room_id
      rq.request('meeting/date', { room_id: room_id, date: date }, function (result) {
        if (result.code == 0) {
          console.log(result.data);
          that.showModal(result.data);
        } else {
          wx.showToast({
            title: result.msg,
            icon: 'none'
          })
        }
      })
    }
    this.setData({
      date: date
    })
  },
  showModal(data) {
    console.log(data);
    if (data.length) {
      this.setData({
        date_arrange: data
      })
    } else {
      this.setData({
        date_arrange: null
      })
    }
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
})